﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IHISCETeim.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using IHISCETeim.Model;

namespace IHISCETeim.DAL
{
    public class UWarrantyCardExDAL
    {
        public static IDataReader GetByUWCID(int UWCID)
	    {
		    Database DB = DatabaseFactory.CreateDatabase();		
		
            DbCommand dbCommand = DB.GetStoredProcCommand("UWarrantyCardEx_GetByUWCID",UWCID);
            return DB.ExecuteReader(dbCommand);
	    }
        public static bool Update(UWarrantyCardExInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("UWarrantyCardEx_Update",obj.UWCID,obj.CustomerName2,obj.CustomerTel2,obj.CustomerMobile2,obj.CustomerIDCard2,obj.CustomerAddress2,obj.CustomerName3,obj.CustomerTel3,obj.CustomerMobile3,obj.CustomerIDCard3,obj.CustomerAddress3);
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch (Exception exc)
            {
                return false;
            }
        }
        /// <summary>
        /// 根据代理商简称,获取其下所有的机器信息
        /// </summary>
        /// <param name="agentname"></param>
        /// <returns></returns>
        public static IDataReader GetByAgentName(string agentname)
        {
            Database DB = DatabaseFactory.CreateDatabase();
            //agentname=agentname.
            if (!string.IsNullOrEmpty(agentname))
            {
                agentname = "'" + agentname + "'";
                agentname = agentname.Replace(",", "','");
            }
          
            DbCommand dbCommand = DB.GetStoredProcCommand("UWarrantyCardEx_GetByAgentName", agentname);
            return DB.ExecuteReader(dbCommand);
        }
    }
}
